<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 2021/3/30
 * Time: 15:36
 */

namespace common\wodrow\wyiibackup;


use yii\base\Component;
use yii\base\Exception;

class WYiiBackup extends Component
{
    /**
     * @var FileJobBackup[]
     */
    public $fileJobs = [];

    /**
     * @var DbJobBackup[]
     */
    public $dbJobs = [];

    /**
     * @var ConfigJobBackup[]
     */
    public $configJobs = [];

    public function init()
    {
        parent::init(); // TODO: Change the autogenerated stub
    }

    /**
     * @throws Exception
     * @throws \yii\base\InvalidConfigException
     */
    public function backup()
    {
        foreach ($this->configJobs as $k => $v) {
            $job = \Yii::createObject($v);
            $job->backupKeep();
            $job->backupWaitUpload();
        }
        foreach ($this->dbJobs as $k => $v) {
            /**
             * @var DbJobBackup $job
             */
            $job = \Yii::createObject($v);
            $job->dbBackupKeep();
            $job->dbBackupWaitUpload();
        }
        foreach ($this->fileJobs as $k => $v) {
            /**
             * @var FileJobBackup $job
             */
            $job = \Yii::createObject($v);
            $job->fileSysBackup();
        }
    }
}